package sz.com.battleship.game.adapters;

import sz.com.battleship.R;
import sz.com.battleship.game.GameElement.GameBoard;
import sz.com.battleship.game.GameElement.Ship;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;

public class shipAdapter extends BaseAdapter{
	private static final int MAX_COUNT = 100;
	private Context mContext;
	private GameBoard gameBoard;
	
	public shipAdapter(Context c) {
		mContext = c;
	}
	public shipAdapter(Context c, GameBoard board){
		mContext = c;
		gameBoard = board;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return MAX_COUNT;
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return shipPictures[position];
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
        ImageView imageView;
        if (convertView == null) {  // if it's not recycled, initialize some attributes
            imageView = new ImageView(mContext);
            imageView.setLayoutParams(new GridView.LayoutParams(50, 50));
            imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
            imageView.setPadding(0, 0, 0, 0);
        } else {
            imageView = (ImageView) convertView;
        }
        if(gameBoard.hasShip(position)){
    		Ship ship = gameBoard.getShip(position);
    		imageView.setImageResource(shipPictures[ship.getType()]);
    	}
        
        return imageView;
    }

	private Integer[] shipPictures = {
    		R.drawable.battlecruser, R.drawable.carrier , R.drawable.medivac , R.drawable.phoenix, R.drawable.viking
    };

    public Integer getBattlecruser(){
    	return shipPictures[0];
    }

    public Integer getCarrier(){
    	return shipPictures[1];
    }

    public Integer getMedivac(){
    	return shipPictures[2];
    }

    public Integer getPhoenix(){
    	return shipPictures[3];
    }
    
    public Integer getViking(){
    	return shipPictures[4];
    }
}
